<?php //pr($batchListData);?>
<!-- Add fancyBox main JS and CSS files -->
<?php
    echo $this->Html->script('fancybox/jquery.fancybox.js');
    echo $this->Html->css('fancybox/jquery.fancybox.css');
?>
<style type="text/css">
    .fancybox-custom .fancybox-skin {
            box-shadow: 0 0 50px #222;
    }
</style>
<div class="right-panel">
    <!--cont-top Start-->
    <div class="cont-top">
        <div class="left-cr"></div>
        <div class="right-cr"></div>
    </div>
    <!--cont-top End-->
    <!---left-nav Sart-->
    <div class="right-nav">
        <?php
        echo $this->session->flash();
        //echo $this->Form->create("ServiceUnit");
        ?>
        <h2>
            <?php echo __('PAYROLL_BATCH_MAINTENANCE'); ?>
            <span  class="back-align">
                <?php echo $this->html->link('<< ' . __('BACK', true), array('controller' => 'payrolls', 'action' => 'index'), array('div' => false, 'alt' => '<< ' . __('BACK', true), 'title' => '<< ' . __('BACK', true), 'class' => 'back-nav', 'escape' => false)); ?>
            </span>
        </h2>
        <div class="top-btns">
            <?php echo $this->Form->create("",array("method"=>"POST","id"=>"searchStaff"));?>
            <table width="100%" cellpadding="2" cellspacing="2" border="0">
                <tr>
		<td width="12%" align="right"><b><?php echo __('SEARCH');?>:<b></td>
		<td width="40%"  align="left">
			<?php
                        echo $this->Form->input('search_criteria', array('maxlength'=>'100','class'=>'text-input normal-wdh required','label'=>false,'div'=>false)); ?>
		</td>
                <td align="left" width="30%">
                    <?php
                    $options = array(1 => 'Show All', 2 => 'On Hold Only');
                    $attributes = array('legend' => false, 'default' => 1);
                    echo $this->Form->radio('holdShow', $options, $attributes);
                    ?>
                </td>
	    	<td align="left" width="25%">
                    <div class="actionbtns">
			<?php
			echo $this->Js->submit(__('SEARCH',true), array('update' => '#divUpdate', "class"=>"button",'label'=>false, 'div' => false, 'before' => $this->Js->get('#divUpdate')->effect('fadeOut'), 'success' => $this->Js->get('#divUpdate')->effect('fadeIn')));
			 ?>
			<div class="buttonEnding"></div>
                </div>
	    	</td>
                
                </tr>
            </table>
            <?php echo $this->Form->end();?>
        </div>
        <!--register Starts-->
        <div class="register" style="border: none;">
            <h3 style="padding-top:10px;"><?php echo __('SELECTED_BATCH_DETAIL'); ?></h3>
            <!-- Div update starts here -->
            <div id="divUpdate">
                <?php echo $this->element('payrolls/payable_list');?>
            </div>
            <!-- Div update ends here -->

            <div class="form-padd" style="background: #ffffff;">
                <!--introduction Start-->
                <div class=" introduction">  
                    <table style="width:100%;">
                        <tr>
                            <td style="width:10%;"><strong><?php echo __('UNIT_CODE');?> :</strong> </td>
                            <td ><?php echo $batchListData['BatchList']['unit_code']; ?></td>
                        </tr>
                        
                        <tr>
                            <td colspan="2">
                                <?php 
                                    echo $this->Form->create("Payroll", array('action' => 'changeStatus')); 
                                    echo $this->Form->hidden("Payroll.batch_list_id", array('value' => $batchListData['BatchList']['id'])); 
                                ?>
                                <table style="width:100%;" class="list" cellpadding="5">
                                    <tr>
                                        <th style="width:12%">&nbsp;</th>
                                        <th style="width:22%; text-align: left;"><strong><?php echo __('CREATED_BY')?></strong></th>
                                        <th style="width:22%; text-align: left;"><strong><?php echo __('VERIFIED_BY')?></strong></th>
                                        <th style="width:22%; text-align: left;"><strong><?php echo __('ENDORSE_BY')?></strong></th>
                                        <th style="width:22%; text-align: left;" ><strong><?php echo __('APPROVED_BY')?></strong></th>
                                        <?php if($batchListData['BatchList']['approved_by'] == 0){?>
                                        <th style="width:12%">&nbsp;</th>
                                        <?php }?>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td><?php echo ($batchListData['BatchList']['prepared_by']) ? $usersData[$batchListData['BatchList']['prepared_by']] : ''?></td>
                                        <td><?php echo ($batchListData['BatchList']['verified_by']) ? $usersData[$batchListData['BatchList']['verified_by']] : ''?></td>
                                        <td><?php echo ($batchListData['BatchList']['endorse_by']) ? $usersData[$batchListData['BatchList']['endorse_by']] : ''?></td>
                                        <td style="border: none;"><?php echo ($batchListData['BatchList']['approved_by']) ? $usersData[$batchListData['BatchList']['approved_by']] : ''?></td>
                                    </tr>
                                    <tr>
                                        <td><?php echo __('DATE'); ?></td>
                                        <td><?php echo date('M j, Y', strtotime($batchListData['BatchList']['prepared_date'])); ?></td>
                                        <td><?php echo ($batchListData['BatchList']['verified_date'] != '0000-00-00') ? date('M j, Y', strtotime($batchListData['BatchList']['verified_date'])) :  __('YET_TO_VERIFY'); ?></td>
                                        <td><?php echo ($batchListData['BatchList']['endorse_date'] != '0000-00-00') ? date('M j, Y', strtotime($batchListData['BatchList']['endorse_date'])) :  __('YET_TO_ENDORSE'); ?></td>
                                        <td style="border: none;"><?php echo ($batchListData['BatchList']['approved_date'] != '0000-00-00') ? date('M j, Y', strtotime($batchListData['BatchList']['approved_date'])) :  __('YET_TO_APPROVE'); ?></td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td>
                                            <?php
                                            $returnFunVerify = "";
                                            $disableClassVerify = "";
                                            $returnFunVerifyRevert = "";
                                            $disableClassVerifyRevert = "";
                                            $returnFunEndorse = "";
                                            $disableClassEndorse = "";
                                            $returnFunEndorseRevert = "";
                                            $disableClassEndorseRevert = "";
                                            $returnFunApprove = "";
                                            $disableClassApprove = "";
                                            $disableClassApproveRevert = "";
                                            $returnFunApproveRevert = "";
                                            $disableClassApproveRevertAll = "";
                                            $returnFunApproveRevertAll = "";
                                            $disableClassApproveAll = "";
                                            $returnFunApproveAll = "";
                                            
                                            if($roleId){//No checks for super admin
                                                if(!$showBatchRequestVerifyURL && !$showBatchRequestApproveURL){//Check if verify permissions is granted
                                                    $returnFunVerify = "return false";
                                                    $disableClassVerify = "disable";
                                                    $disableClassVerifyRevert = "disable";
                                                    $returnFunVerifyRevert = "return false";
                                                    $disableClassApproveRevertAll = "disable";
                                                    $returnFunApproveRevertAll = "return false";
                                                    $disableClassApproveAll = "disable";
                                                    $returnFunApproveAll = "return false";
                                                }
                                                if(!$showBatchRequestEndorseURL && !$showBatchRequestApproveURL){//Check if endorse permissions is granted
                                                    $disableClassEndorse = "disable";
                                                    $returnFunEndorse = "return false";
                                                    $disableClassEndorseRevert = "disable";
                                                    $returnFunEndorseRevert = "return false";
                                                    $disableClassApproveRevertAll = "disable";
                                                    $returnFunApproveRevertAll = "return false";
                                                    $disableClassApproveAll = "disable";
                                                    $returnFunApproveAll = "return false";
                                                }
                                                
                                                if(!$showBatchRequestApproveURL){
                                                    $returnFunApprove = "return false";
                                                    $disableClassApprove = "disable";
                                                    $disableClassApproveRevert = "disable";
                                                    $returnFunApproveRevert = "return false";
                                                    $disableClassApproveRevertAll = "disable";
                                                    $returnFunApproveRevertAll = "return false";
                                                    $disableClassApproveAll = "disable";
                                                    $returnFunApproveAll = "return false";
                                                }
                                            }
                                            
                                            if($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['verified_by'] == 0){
                                                echo $this->Form->submit(__('VERIFY', true), array(
                                                    "class" => "button ".$disableClassVerify, 
                                                    'label' => false, 
                                                    'div' => false,
                                                    'name' => 'verify',
                                                    'onClick' => $returnFunVerify
                                                    ));
                                                echo '<div class="buttonEnding"></div>';
                                            }else{
                                                if($batchListData['BatchList']['endorse_by'] != 0 || $batchListData['BatchList']['approved_by'] != 0){
                                                    $disableClassVerifyRevert = "disable";
                                                    $returnFunVerifyRevert = "return false";
                                                }
                                                echo $this->Form->submit(__('REVERT', true), array(
                                                    "class" => "button ".$disableClassVerifyRevert, 
                                                    'label' => false, 
                                                    'div' => false,
                                                    'name' => 'revert',
                                                    'onClick' => $returnFunVerifyRevert
                                                ));
                                                echo '<div class="buttonEnding"></div>';
                                            }
                                            echo '</td><td >';

                                            if($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['endorse_by'] == 0){
                                                
                                                if($batchListData['BatchList']['verified_by'] == 0){
                                                    $disableClassEndorse = "disable";
                                                    $returnFunEndorse = "return false";
                                                }
                                                echo $this->Form->submit(__('ENDORSE', true), array(
                                                    "class" => "button ".$disableClassEndorse, 
                                                    'label' => false, 
                                                    'div' => false,
                                                    'name' => 'endorse',
                                                    'onClick' => $returnFunEndorse
                                                    ));
                                                echo '<div class="buttonEnding"></div>';
                                            }else{
                                                if($batchListData['BatchList']['approved_by'] != 0){
                                                    $disableClassEndorseRevert = "disable";
                                                    $returnFunEndorseRevert = "return false";
                                                }
                                                echo $this->Form->submit(__('REVERT', true), array(
                                                    "class" => "button ".$disableClassEndorseRevert, 
                                                    'label' => false, 
                                                    'div' => false,
                                                    'name' => 'revert_endorse',
                                                    'onClick' => $returnFunEndorseRevert
                                                ));
                                                echo '<div class="buttonEnding"></div>';
                                            }
                                            echo '</td><td>';
                                            
                                            if($batchListData['BatchList']['approved_by'] == 0){
                                                if($batchListData['BatchList']['verified_by'] == 0 || $batchListData['BatchList']['endorse_by'] == 0){
                                                    $disableClassApprove = "disable";
                                                    $returnFunApprove = "return false";
                                                }
                                                echo $this->Form->submit(__('APPROVE', true), array(
                                                    "class" => "button ".$disableClassApprove, 
                                                    'label' => false, 
                                                    'div' => false,
                                                    'name' => 'approve',
                                                    'onClick' => $returnFunApprove
                                                ));
                                                echo '<div class="buttonEnding"></div>';
                                               
                                            }elseif($batchListData['BatchList']['approved_by'] != 0){
                                                if($batchListData['BatchList']['checker'] == 0){
                                                    echo $this->Form->submit(__('REVERT', true), array(
                                                        "class" => "button ".$disableClassApproveRevert, 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'name' => 'revert_approved',
                                                        'onClick' => $returnFunApproveRevert
                                                    ));
                                                    echo '<div class="buttonEnding"></div>';
                                                } else{
                                                    echo $this->Form->submit(__('CHECKING', true), array(
                                                        "class" => "button disable", 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'onClick' => 'return false;',
                                                    ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }
                                            }
                                            
                                            echo '</td><td>';
                                            if($batchListData['BatchList']['approved_by'] == 0){
                                                echo $this->Form->submit(__('APPROVE_ALL', true), array(
                                                    "class" => "button ".$disableClassApproveAll, 
                                                    'label' => false, 
                                                    'div' => false,
                                                    'name' => 'approve_all',
                                                    'onClick' => $returnFunApproveAll
                                                ));
                                                echo '<div class="buttonEnding"></div>';
                                               
                                            }elseif($batchListData['BatchList']['approved_by'] != 0){
                                                if($batchListData['BatchList']['checker'] == 0){
                                                    echo $this->Form->submit(__('REVERT_ALL', true), array(
                                                        "class" => "button ".$disableClassApproveRevertAll, 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'name' => 'revert_all',
                                                        'onClick' => $returnFunApproveRevertAll
                                                    ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }else{
                                                    echo $this->Form->submit(__('CHECKING', true), array(
                                                        "class" => "button disable", 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'onClick' => 'return false;',
                                                    ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }
                                            }
                              
                                            
                                            /*
                                            if(!$roleId){//No checks for super admin
                                                if($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['verified_by'] == 0){
                                                    echo $this->Form->submit(__('VERIFY', true), array(
                                                        "class" => "button", 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'name' => 'verify'
                                                        ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }elseif($batchListData['BatchList']['endorse_by'] == 0 && $batchListData['BatchList']['approved_by'] == 0){
                                                    echo $this->Form->submit(__('REVERT', true), array(
                                                        "class" => "button", 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'name' => 'revert'
                                                    ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }
                                                echo '</td><td >';

                                                if($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['endorse_by'] == 0 && $batchListData['BatchList']['verified_by'] != 0){
                                                    echo $this->Form->submit(__('ENDORSE', true), array(
                                                        "class" => "button", 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'name' => 'endorse'
                                                        ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }elseif($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['endorse_by'] != 0){
                                                    echo $this->Form->submit(__('REVERT', true), array(
                                                        "class" => "button", 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'name' => 'revert_endorse'
                                                    ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }
                                                echo '</td><td>';
                                                
                                                if($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['verified_by'] != 0 && $batchListData['BatchList']['endorse_by'] != 0){
                                                    echo $this->Form->submit(__('APPROVE', true), array(
                                                        "class" => "button", 
                                                        'label' => false, 
                                                        'div' => false,
                                                        'name' => 'approve'
                                                    ));
                                                    echo '<div class="buttonEnding"></div>';
                                                   
                                                }elseif($batchListData['BatchList']['approved_by'] != 0){
                                                    if($batchListData['BatchList']['checker'] == 0){
                                                        echo $this->Form->submit(__('REVERT', true), array(
                                                            "class" => "button", 
                                                            'label' => false, 
                                                            'div' => false,
                                                            'name' => 'revert_approved'
                                                        ));
                                                        echo '<div class="buttonEnding"></div>';
                                                    } else{
                                                        echo $this->Form->submit(__('CHECKING', true), array(
                                                            "class" => "button disable", 
                                                            'label' => false, 
                                                            'div' => false,
                                                            'onClick' => 'return false;',
                                                        ));
                                                        echo '<div class="buttonEnding"></div>';
                                                    }
                                                }
                                
                                            }else{//BASED ON PERMISSIONS
                                                if($showBatchRequestVerifyURL || $showBatchRequestApproveURL){
                                                    if($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['verified_by'] == 0){
                                                        echo $this->Form->submit(__('VERIFY', true), array(
                                                            "class" => "button", 
                                                            'label' => false, 
                                                            'div' => false,
                                                            'name' => 'verify'
                                                            ));
                                                        echo '<div class="buttonEnding"></div>';
                                                    }else{//No checks for verifier or approver
                                                        if($batchListData['BatchList']['endorse_by'] == 0 && $batchListData['BatchList']['approved_by'] == 0){
                                                            echo $this->Form->submit(__('REVERT', true), array(
                                                                "class" => "button", 
                                                                'label' => false, 
                                                                'div' => false,
                                                                'name' => 'revert'
                                                            ));
                                                            echo '<div class="buttonEnding"></div>';
                                                        }
                                                    }
                                                    
                                                }
                                                echo '</td><td >';
                                                if($showBatchRequestEndorseURL || $showBatchRequestApproveURL){//No checks for superadmin
                                                    if($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['endorse_by'] == 0 && $batchListData['BatchList']['verified_by'] != 0){
                                                        echo $this->Form->submit(__('ENDORSE', true), array(
                                                            "class" => "button", 
                                                            'label' => false, 
                                                            'div' => false,
                                                            'name' => 'endorse'
                                                            ));
                                                        echo '<div class="buttonEnding"></div>';
                                                    }else{//No checks for endorser or approver
                                                        if($batchListData['BatchList']['approved_by'] == 0 && $batchListData['BatchList']['endorse_by'] != 0){
                                                            echo $this->Form->submit(__('REVERT', true), array(
                                                                "class" => "button", 
                                                                'label' => false, 
                                                                'div' => false,
                                                                'name' => 'revert_endorse'
                                                            ));
                                                            echo '<div class="buttonEnding"></div>';
                                                        }
                                                    }
                                                    
                                                }

                                                echo '</td><td>';
                                                if($showBatchRequestApproveURL && $batchListData['BatchList']['verified_by'] != 0 && $batchListData['BatchList']['endorse_by'] != 0){
                                                    if($batchListData['BatchList']['approved_by'] == 0){
                                                        echo $this->Form->submit(__('APPROVE', true), array(
                                                            "class" => "button", 
                                                            'label' => false, 
                                                            'div' => false,
                                                            'name' => 'approve'
                                                        ));
                                                        echo '<div class="buttonEnding"></div>';
                                                       
                                                    }elseif($batchListData['BatchList']['approved_by'] != 0){
                                                        if($batchListData['BatchList']['checker'] == 0){
                                                            echo $this->Form->submit(__('REVERT', true), array(
                                                                "class" => "button", 
                                                                'label' => false, 
                                                                'div' => false,
                                                                'name' => 'revert_approved'
                                                            ));
                                                            echo '<div class="buttonEnding"></div>';
                                                        } else{
                                                            echo $this->Form->submit(__('CHECKING', true), array(
                                                                "class" => "button disable", 
                                                                'label' => false, 
                                                                'div' => false,
                                                                'onClick' => 'return false;',
                                                            ));
                                                            echo '<div class="buttonEnding"></div>';
                                                        }
                                                    }
                                                }
                                                echo '</td><td>';
                                                if($showBatchRequestApproveURL){
                                                    if($batchListData['BatchList']['approved_by'] == 0){
                                                        echo $this->Form->submit(__('APPROVE_ALL', true), array(
                                                            "class" => "button", 
                                                            'label' => false, 
                                                            'div' => false,
                                                            'name' => 'approve_all'
                                                        ));
                                                        echo '<div class="buttonEnding"></div>';
                                                       
                                                    }elseif($batchListData['BatchList']['approved_by'] != 0){
                                                        if($batchListData['BatchList']['checker'] == 0){
                                                            echo $this->Form->submit(__('REVERT_ALL', true), array(
                                                                "class" => "button", 
                                                                'label' => false, 
                                                                'div' => false,
                                                                'name' => 'revert_all'
                                                            ));
                                                            echo '<div class="buttonEnding"></div>';
                                                        }
                                                    }
                                                }
                                            }
                                            */
                                            
                                            ?>
                                        </td>
                                    </tr>
                                </table>
                                <?php echo $this->Form->end(); ?>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:100%" colspan="2">
                                 <?php 
                                    echo $this->Form->create("Payroll", array('action' => 'download_view')); 
                                    echo $this->Form->hidden("Payroll.batch_list_id", array('value' => $batchListData['BatchList']['id'])); 
                                 ?>
                                <table align="center" cellspacing="10"> 
                                    <tr>
                                        <td>
                                            <?php
                                                if(!$roleId){//No checks for superadmin
                                                    echo $this->Form->submit(__('PRINT_TO_PDF', true), array(
                                                            "class" => "button", 
                                                            'label' => false, 
                                                            'div' => false,
                                                            'name' => 'print_pdf'
                                                        ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }elseif($showBatchRequestDownloadPDFURL){
                                                    echo $this->Form->submit(__('PRINT_TO_PDF', true), array(
                                                            "class" => "button", 
                                                            'label' => false, 
                                                            'div' => false,
                                                            'name' => 'print_pdf'
                                                        ));
                                                    echo '<div class="buttonEnding"></div>';
                                                }
                                            ?>    
                                        </td>
                                        <td>
                                            <?php
                                            if(!$roleId){//No checks for superadmin
                                                echo $this->Form->submit(__('PRINT_TO_EXCEL', true), array(
                                                    "class" => "button", 
                                                    'label' => false, 
                                                    'div' => false,
                                                    'name' => 'print_excel'
                                                ));
                                                echo '<div class="buttonEnding"></div>';
                                            }elseif($showBatchRequestDownloadExcelURL){
                                                echo $this->Form->submit(__('PRINT_TO_EXCEL', true), array(
                                                    "class" => "button", 
                                                    'label' => false, 
                                                    'div' => false,
                                                    'name' => 'print_excel'
                                                ));
                                                echo '<div class="buttonEnding"></div>';
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <?php
                                            if(!$roleId){//No checks for superadmin
                                                echo $this->Html->link(__('EMAIL', true), array(
                                                    'controller' => 'payrolls', 'action' => 'sendMail', $batchListData['BatchList']['id']), array(
                                                    'class' => 'button fancybox fancybox.ajax', 'style' => 'font-weight:normal;')
                                                );
                                                echo '<div class="buttonEnding"></div>';
                                            }elseif($showBatchRequestEmailURL){
                                                echo $this->Html->link(__('EMAIL', true), array(
                                                    'controller' => 'payrolls', 'action' => 'sendMail', $batchListData['BatchList']['id']), array(
                                                    'class' => 'button fancybox fancybox.ajax', 'style' => 'font-weight:normal;')
                                                );
                                                echo '<div class="buttonEnding"></div>';
                                            }
                                            ?>
                                        </td>
                                    </tr>
                                </table>
                                <?php echo $this->Form->end(); ?>
                            </td>
                        </tr>
                    </table>
                    
                </div>
                <!--introduction End-->
                <div class="clear"></div>
            </div>
        </div>        
    </div>
</div>
<script>   
    $(document).ready(function() {
        $('.fancybox').fancybox();
    });
    
</script>